#define _CRT_SECURE_NO_WARNINGS 1

struct ListNode {
    int val;
    struct ListNode *next;
    ListNode(int x) : val(x), next(NULL) {}
};
class PalindromeList {
public:
    struct ListNode* reservelist(ListNode* h)
    {
        struct ListNode* cur = h;
        struct ListNode* prev = NULL;
        struct ListNode* next = NULL;

        while (cur)
        {
            next = cur->next;
            cur->next = prev;
            prev = cur;
            cur = next;
        }
        return prev;
    }
    bool chkPalindrome(ListNode* A) {
        // write code here
        struct ListNode* head = A;
        int num = 0;
        while (head)
        {
            num++;
            head = head->next;
        }
        struct ListNode* fast = A;
        struct ListNode* slow = A;
        while (fast && fast->next)
        {
            fast = fast->next->next;
            slow = slow->next;
        }
        if (num % 2 != 0)
        {
            slow = slow->next;
        }
        struct ListNode* a = reservelist(slow);
        struct ListNode* b = A;
        while (a && b)
        {
            if (a->val != b->val)
            {
                return false;
            }
            else {
                a = a->next;
                b = b->next;
            }
        }
        return true;

    }
};